package com.lenovo.smarttraffic.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;

import com.lenovo.smarttraffic.Interface.ItemInterface;
import com.lenovo.smarttraffic.R;
import com.lenovo.smarttraffic.ui.adapter.SmartTrafficRvAdapter;

import java.util.ArrayList;
import java.util.List;

public class SmartTrafficActivity extends BaseActivity implements ItemInterface, NavigationView.OnNavigationItemSelectedListener {

    private static final String TAG = "SmartTrafficActivity";

    private RecyclerView smartTrafficRecyclerView;
    private ArrayList<List> itemData = new ArrayList<>();
    private Toolbar stToolbar;
    private DrawerLayout stDrawer;
    private NavigationView mStNav;

    @Override
    protected int getLayout() {
        return R.layout.activity_smart_traffic;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
        initData();
        initEvent();
    }

    private void initData() {
        ArrayList<Object> list = new ArrayList<>();
        list.add(R.mipmap.icon101);
        list.add("环境指标");
        itemData.add(list);

        list = new ArrayList<>();
        list.add(R.mipmap.icon102);
        list.add("手动控制");
        itemData.add(list);

        list = new ArrayList<>();
        list.add(R.mipmap.icon103);
        list.add("系统设置");
        itemData.add(list);

        list = new ArrayList<>();
        list.add(R.mipmap.icon104);
        list.add("农信贷");
        itemData.add(list);

        list = new ArrayList<>();
        list.add(R.mipmap.icon_yue);
        list.add("农电微商");
        itemData.add(list);

        list = new ArrayList<>();
        list.add(R.mipmap.icon_trafic);
        list.add("资讯通");
        itemData.add(list);

        list = new ArrayList<>();
        list.add(R.mipmap.video_icon);
        list.add("创意");
        itemData.add(list);

        SmartTrafficRvAdapter sv = new SmartTrafficRvAdapter(itemData);
        smartTrafficRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL));
        smartTrafficRecyclerView.setAdapter(sv);
    }

    private void initEvent() {
        stToolbar.setNavigationOnClickListener(v -> stDrawer.openDrawer(GravityCompat.START));
        mStNav.setNavigationItemSelectedListener(this);
    }

    private void initView() {

        smartTrafficRecyclerView = findViewById(R.id.smart_traffic_recycler_view);
        stToolbar = findViewById(R.id.st_toolbar);
        stToolbar.setNavigationIcon(R.mipmap.theme_toolbar_btn_menu_fg_normal);
        stDrawer = findViewById(R.id.st_drawer);
        mStNav = findViewById(R.id.st_nav);
    }


    @Override
    public void tapItem(View item, String title) {
        item.setOnClickListener((View v) -> {
            Log.i(TAG, "tapItem: " + title);
            Intent intent = new Intent(v.getContext(), STActivityChild.class);
            intent.putExtra("item", title);
            v.getContext().startActivity(intent);
        });
    }

    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        return false;
    }
}
